package cc.wsyw126.java.nowcoder.interview;

import cc.wsyw126.java.lintCode.swap_two_nodes_in_linked_list.ListNode;

import java.util.LinkedList;

/**
 * Created by Administrator on 2017/4/24.
 * 给定一个链表ListNode* pHead，请返回一个bool，代表链表是否为回文。
 */
public class Palindrome {
    public boolean isPalindrome(ListNode pHead) {
        LinkedList<Integer> val = new LinkedList<>();
        while (pHead!=null) {
            val.add(pHead.val);
            pHead=pHead.next;
        }
        while (!val.isEmpty() && val.size() >1) {
            Integer first = val.removeFirst();
            Integer last = val.removeLast();
            if (first != last) {
                return false;
            }
        }
        return true;
    }
}
